unit F_AM;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, JvExControls, JvSpeedButton, ExtCtrls, ZDataset, StdCtrls;

type
  TF_AltaModificacion = class(TForm)
    PanelInferior: TPanel;
    JvSB_Aceptar: TJvSpeedButton;
    JvSB_Cancelar: TJvSpeedButton;
    PanelCentral: TPanel;
    procedure JvSB_CancelarClick(Sender: TObject);
    procedure JvSB_AceptarClick(Sender: TObject);
    procedure NumericEditKeyPress(Sender: TObject;  var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
    ID:Integer;
    Modifing: Boolean;
    function GetNewID(Field:String; Table:TZTable):integer;

    procedure Agregar; virtual; abstract;
    procedure Modificar; virtual; abstract;
    procedure SetCurrentData; virtual; abstract;
    function ValidarCampos: boolean; virtual; abstract;

    constructor Create (var owner: TComponent); overload;
    constructor Create (var owner: TComponent; IDentificador:integer); overload;
  end;

var
  F_AltaModificacion: TF_AltaModificacion;

implementation

{$R *.dfm}

constructor TF_AltaModificacion.Create (var owner:TComponent);
begin
  inherited Create(owner);
  Modifing:= False;
end;

constructor TF_AltaModificacion.Create (var owner:TComponent; IDentificador:integer);
begin
  inherited Create(owner);
  ID:= IDentificador;
  Modifing:= True;
  SetCurrentData;
end;

procedure TF_AltaModificacion.JvSB_CancelarClick(Sender: TObject);
begin
  ModalResult:= mrCancel;
end;

procedure TF_AltaModificacion.JvSB_AceptarClick(Sender: TObject);
begin
  if (ValidarCampos) then
    begin
      if not (Modifing) then
        Agregar
      else
        Modificar;
      ModalResult:= mrOK;
    end;
end;

function TF_AltaModificacion.GetNewID(Field:String;Table:TZTable):integer;
var
  aux:integer;
begin
  Table.Filtered:=False;
  Table.SortedFields:= Field+' ASC';
  Table.Last;
  aux:=Table.FieldByName(Field).AsInteger+1;
  Table.Filtered:=True;
  GetNewID:=aux;
end;

procedure TF_AltaModificacion.NumericEditKeyPress(Sender: TObject;  var Key: Char);
begin
  if not ((Key in ['0'..'9', #0..#31]) or ((Key in ['/',',']) and ((Pos('/', TEdit(Sender).Text) = 0) and (Pos(',', TEdit(Sender).Text) = 0)) and (Length(TEdit(Sender).Text)>0))) then
    begin
      Key := #0;
      MessageBeep(MB_ICONEXCLAMATION);
    end
end;

end.
